package com.jindy.module.filing.controller;

import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.filing.domain.FilingProduct;
import com.jindy.module.filing.service.FilingProductService;
import com.jindy.system.service.ISysUserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 报备产品Controller
 *
 * @author zhaoxi
 * @date 2022-12-30
 */
@Api(tags = "业务后台 - 报备产品管理 ")
@RestController
@RequestMapping("/module/filingProduct")
@Validated
@Slf4j
public class FilingProductController extends BaseController {
    @Autowired
    private FilingProductService filingProductService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询报备产品数据列表
     */
//    @PreAuthorize("@ss.hasPermi('module:filingProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilingProduct product){

        //        //添加权限
        //        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        //        filing.setUserId(sysUser.getUserId().toString());

        startPage();
        List<FilingProduct> list = filingProductService.selectFilingProductList(product);
        return getDataTable(list);
    }

    /**
     * 根据id查询报备产品信息
     */
//    @PreAuthorize("@ss.hasPermi('module:filingProduct:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable("id") String id) {
        return AjaxResult.success(filingProductService.selectFilingProductById(id));
    }

    /**
     * 新增报备产品数据
     */
    @Log(title = "新增报备产品", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('module:filingProduct:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FilingProduct product)
    {
        return toAjax(filingProductService.insertFilingProduct(product));
    }

    /**
     * 修改报备产品数据
     */
    @Log(title = "修改报备产品", businessType = BusinessType.UPDATE)
//    @PreAuthorize("@ss.hasPermi('module:filingProduct:update')")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody FilingProduct product) {
        return toAjax(filingProductService.updateFilingProduct(product));
    }

    /**
     * 删除报备产品
     */
    @Log(title = "删除报备产品", businessType = BusinessType.DELETE)
//    @PreAuthorize("@ss.hasPermi('module:filingProduct:delete')")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(filingProductService.deleteFilingProductById(id));
    }

    /**
     * 批量删除
     */
    @Log(title = "批量删除", businessType = BusinessType.DELETE)
//    @PreAuthorize("@ss.hasPermi('module:filingProduct:deletes')")
    @DeleteMapping("/{ids}")
    public AjaxResult removes(@PathVariable String[] ids)
    {
        return toAjax(filingProductService.deleteFilingProductByIds(ids));
    }
}
